package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.activity.able.UserAbleItem;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.pb.bag.BagProto;

import java.util.Collection;

public class BagPb {

	private static BagProto.BagTempMsg.Builder parsItemTempMsg(UserBagItem userBagItem) {
		if(null == userBagItem){
			return null;
		}
		BagProto.BagTempMsg.Builder msg = BagProto.BagTempMsg.newBuilder();
		msg.setGoodsId(userBagItem.getGoodsId());
		msg.setNum(userBagItem.getNum());
		return msg;
	}

	public static BagProto.BagRespMsg.Builder parseBagRespMsg(Collection<UserBagItem> userBagItemList) {
		BagProto.BagRespMsg.Builder listMsg = BagProto.BagRespMsg.newBuilder();
		if(null != userBagItemList) {
			for (UserBagItem bag : userBagItemList) {
				BagProto.BagTempMsg.Builder msg = parsItemTempMsg(bag);
				if (null != msg) {
					listMsg.addItemList(msg);
				}
			}
		}
		return listMsg;
	}

	public static void mergeAbleItem(BagProto.BagRespMsg.Builder builder, Collection<UserAbleItem> userBagItemList) {
		for (UserAbleItem item : userBagItemList) {
			BagProto.BagTempMsg.Builder msg = BagProto.BagTempMsg.newBuilder();
			msg.setGoodsId(item.getGoodsId());
			msg.setNum(item.getNum());
			builder.addItemList(msg);
		}
	}

}
